package com.example.myapplication;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.lidroid.xutils.view.annotation.ViewInject;
import com.example.myapplication.callback.LoginCallBack;
import com.example.myapplication.ic.RegisterInterface;
import com.example.myapplication.ic.RegisterInterfaceImpl;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class RegidterActivity extends AppCompatActivity implements View.OnClickListener,LoginCallBack {
    @ViewInject(R.id.teacher_name)
    private EditText name;
    @ViewInject(R.id.teacher_password)
    private EditText pass;
    @ViewInject(R.id.teacher_email)
    private EditText email;
    @ViewInject(R.id.teacher_number)
    private EditText teacherId;
    private ProgressDialog p;
    @ViewInject(R.id.email_resigter_in_button)
    private Button btn;

    private RegisterInterface ri;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_regidter);
        com.lidroid.xutils.ViewUtils.inject(this);
        p = new ProgressDialog(this);
        p.setMessage("加载中...");
        p.setCanceledOnTouchOutside(false);
        ri = new RegisterInterfaceImpl();
        btn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        switch (id) {
            case R.id.email_resigter_in_button:
                boolean regisiterFirst = ri.judgeIsRegister(RegidterActivity.this, name, pass, email, teacherId);
                //     Toast.makeText(RegidterActivity.this,regisiterFirst+"",Toast.LENGTH_LONG).show();
                if (regisiterFirst == false) {
                    p.show();
                    ri.getRegister(RegidterActivity.this, getViewString(name), getViewString(email), getViewString(pass), getViewString(teacherId));
                }
                break;
        }
    }

    String getViewString(EditText view) {
        return view.getText().toString().trim();
    }

    @Override
    public void onSuccess(String info) {
        p.dismiss();
        Log.i("reg", info);
    }


    @Override
    public void onFail(String info) {
        p.dismiss();
        Log.i("reg", info);

    }

}
